package com.lancoo.answer.widget.combinationView;

import android.content.Context;
import android.text.Html;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.lancoo.answer.R;
import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.entity.ExamRequireBean;
import com.lancoo.answer.model.entity.TaskControlBean;

/**
 * Created by pengmi on 2022/2/22 10:38
 * Description:考试要求view
 */
public class TestRequirementView extends RelativeLayout {


    public TestRequirementView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public TestRequirementView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public TestRequirementView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }


    private void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.ev_item_test_answer_sheet_head,this);
    }

    public void setData(){
        TaskControlBean taskControlBean= ConstantBean.Companion.getTaskControlBean();
        if(taskControlBean==null){
            return;
        }
        ExamRequireBean examRequestBean = taskControlBean.getExamRequireBean();

        if(examRequestBean==null){
            findViewById(R.id.rl_head).setVisibility(GONE);
            return;
        }
        boolean enableShowExamRequirement = examRequestBean.isEnableShowExamRequirement();
        TextView tv_TestName=findViewById(R.id.tv_test_name);
        TextView tv_message=findViewById(R.id.tv_message);
        String testName=examRequestBean.getExamName();
        String totalChild="<strong>"+examRequestBean.getTotalQuesCount()+"</strong>";
        String testLength="<strong>"+examRequestBean.getExamTimeLength()+"</strong>";
        tv_TestName.setText(testName);
        SpannableStringBuilder ssb=new SpannableStringBuilder();
        SpannableString ss1=new SpannableString(Html.fromHtml(totalChild));
        ss1.setSpan(new ForegroundColorSpan(0xff0099ff),0,ss1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        SpannableString ss2=new SpannableString(Html.fromHtml(testLength));
        ss2.setSpan(new ForegroundColorSpan(0xff0099ff),0,ss2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssb.append("本卷共 ");
        ssb.append(ss1);
        ssb.append(" 小题，总时长 ");
        ssb.append(ss2);
        ssb.append(" 分钟");
        if(enableShowExamRequirement){
            ssb.append(" \n纪律：禁止查看资料，视线离开屏幕、交头接耳\n注意事项：疑似舞弊提示后，可继续作答，教师将会公正判别");
        }
        tv_message.setText(ssb);
    }
}
